package net.osc.model.query;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.osc.model.BaseEntity;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;



/**
 * 单个完整的查询单元
 * 
 * @author <a href=mailto:peng.wu@foxmail.com>wu.peng</a> 2012-9-7
 * 
 */
@Entity
@Table(name = "query_unit")
@JsonIgnoreProperties({ "querySegments" })
public class QueryUnit extends BaseEntity {

	public static final String QUERY_TYPE_SQL = "sql";
	public static final String QUERY_TYPE_HQL = "hql";

	/** 关键字 */
	private String key;

	/** 类型：sql/hql */
	private String type;

	/** 内容 */
	private String text;
	
	/** 描述 */
	private String description;

	/** 动态拼接段 */
	private List<QuerySegment> querySegments = new ArrayList<QuerySegment>();

	@Column(name = "query_key", length = 200)
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Column(name = "query_type", length = 100)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Lob
	@Column(name = "query_text")
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	@Column(length = 500)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Transient
	public List<QuerySegment> getQuerySegments() {
		return querySegments;
	}

	public void setQuerySegments(List<QuerySegment> querySegments) {
		this.querySegments = querySegments;
	}

}
